package com.codemeta.bokit.sample.all.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hice
 * @date 2021/11/19
 */
@RestController
@RequestMapping
public class LoginController {

    @PostMapping("/login")
    public JSONObject login() {
        StpUtil.login(10011);
        return new JSONObject().fluentPut("login", 10011);
    }

    @PostMapping("/register")
    public JSONObject register() {
        return new JSONObject().fluentPut("register", 10011);
    }

    @GetMapping("/logout")
    public JSONObject logout() {
        Object loginId = StpUtil.getLoginId();
        StpUtil.logout();
        return new JSONObject().fluentPut("logout", loginId);
    }
}